package com.cpp.server.controller;

import com.cpp.common.constant.ModuleConstant;
import com.cpp.common.result.PageResult;
import com.cpp.common.result.Result;
import com.cpp.pojo.dto.exam.ExamCreateDTO;
import com.cpp.pojo.dto.exam.ExamPageDTO;
import com.cpp.pojo.dto.exam.ExamSubmitDTO;
import com.cpp.pojo.vo.exam.ExamPaperVO;
import com.cpp.pojo.vo.question.QuestionCreateConfirmVO;
import com.cpp.pojo.vo.summary.ExamReport;
import com.cpp.server.aspect.annotation.MyLog;
import com.cpp.server.service.ExamService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/exam")
@MyLog(module = ModuleConstant.OTHERS)
public class ExamController {
    private final ExamService examService;
//    后端->分页查询未考试列表                    ->查询考试题目          ->提交考试     ->返回考试成绩                     ->给老师返回分析报告

    // 创建考试
    @MyLog(module = ModuleConstant.PRE_EXAM)
    @PostMapping("/create")
    public Result<QuestionCreateConfirmVO> createExam(@RequestBody ExamCreateDTO examCreateDTO) {
        examService.createExam(examCreateDTO);
        return Result.success();
    }
    //查询考试题目
    @MyLog(module = ModuleConstant.PRE_EXAM)
    @GetMapping("/getExamQuestion")
    public Result<QuestionCreateConfirmVO> getExamQuestion(@RequestParam Long examId) {
        QuestionCreateConfirmVO questionCreateConfirmVO = examService.getExamQuestionConfirm(examId);
        return Result.success(questionCreateConfirmVO);
    }
    //查询没有确认的考试题目
    @MyLog(module = ModuleConstant.PRE_EXAM)
    @GetMapping("/getExamQuestionConfirm")
    public Result<QuestionCreateConfirmVO> getExamQuestionConfirm() {
        QuestionCreateConfirmVO questionCreateConfirmVO = examService.getExamQuestionNoConfirm();
        return Result.success(questionCreateConfirmVO);
    }
    //分页查询考试列表
    @GetMapping("/list")
    public Result<PageResult> listExam(ExamPageDTO examPageDTO) {
        PageResult result  = examService.pageExam(examPageDTO);
        return Result.success(result);
    }
    //开始考试，查询考试题目，修改记录考试状态
    @MyLog(module = ModuleConstant.EXAM)
    @GetMapping("/startExam")
    public Result<ExamPaperVO> startExam(@RequestParam Long examId) {
        ExamPaperVO examPaperVO = examService.startExam(examId);
        return Result.success(examPaperVO);
    }
    //提交考试，修改考试记录状态，统计成绩
    @MyLog(module = ModuleConstant.EXAM)
    @PostMapping("/submitExam")
    public Result submitExam(@RequestBody ExamSubmitDTO examSubmitDTO) {
            examService.submitExam(examSubmitDTO);
        return Result.success();
    }
    //查询考试成绩
    @MyLog(module = ModuleConstant.EXAM)
    @GetMapping("/getExamScore")
    public Result<Integer> getExamScore(@RequestParam Long examId) {
        Integer score = examService.getExamScore(examId);
//        ExamScoreVO examScoreVO = examService.getExamScore(examId);
        return Result.success(score);
    }
//    返回考试分析报告，对学生提交的答案进行自动化检测，提供错误定位与修正建议。对学生整体数据进行分析，总结知识掌握情况与教学建议。
    @GetMapping("/analysisReport")
    @MyLog(module = ModuleConstant.PRE_EXAM)
    public Result<ExamReport> analysisReport(@RequestParam(required = false) Long examId) {
        ExamReport examAnalysisVO = examService.analysisReport(examId);
        return Result.success(examAnalysisVO);
    }
}
